<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>4-8 (新)动态组件与v-once指令</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="root">

    </div>

    <script>
        Vue.component('child-one', {
            template: `
                <div>child-one</div>
            `
        })
        Vue.component('child-two', {
            template: `
                <div>child-two</div>
            `
        })
        var vm = new Vue({
            el: "#root",
            data: {
                type: "child-one"
            },
            methods: {
                handleBtnClick() {
                    this.type = this.type === 'child-one' ? 'child-two' : 'child-one';
                }
            },
            template: `
                <div v-once>
                    <child-one v-if="type === 'child-one'"></child-one>
                    <child-two v-if="type === 'child-two'"></child-two>
                    <button @click="handleBtnClick">change</button>    
                </div>
            `
        })
    </script>
</body>

</html>